import Vue from 'vue'
import axios from 'axios';

import Cookies from 'js-cookie'

/* 解决浏览器默认样式差异normalize.css */
import 'normalize.css/normalize.css'
import Element from 'element-ui'
import '@/styles/index.scss' // global css
import 'element-ui/lib/theme-chalk/index.css';
Element.Dialog.props.lockScroll.default = false;
import 'babel-polyfill'
/* 阿里图标库 */
import '@/assets/iconfont.css';
import 'font-awesome/css/font-awesome.min.css'
import { download } from "@/utils/common";
import { deseHandler } from '@/utils/index';
import '@/utils/rem.js'

/* 复制粘贴 */
import VueClipboard from 'vue-clipboard2'

/* Avue.js */
import Avue from '@smallwei/avue';
import '@smallwei/avue/lib/index.css';

import App from './App.vue'
import router from './router'
import store from './store'

Vue.prototype.$axios = axios;
Vue.prototype.download = download;
Vue.prototype.deseHandler = deseHandler;
// svg-icon组件注册
import './icons' // icon
// 权限验证
import './permission' // permission control

/* 过滤器 */
import * as filters from './filters' // global filters

Element.Table.props.headerCellStyle = {
    type: [Object, Function],
    default: () => {
        return {
            backgroundColor: '#ecf5ff'
        }
    }
}
Vue.use(Element, {
    size: Cookies.get('size') || 'medium', // set element-ui default size
});
Vue.use(Avue, {
    axios
});
Vue.use(VueClipboard)


/** 权限指令,对按钮权限的控制 **/
Vue.directive('has', {
    bind: function (el, binding) {
        if (!Vue.prototype.$_has(binding.value)) {
            el.style.display = "none";
        }
    }
})
// 权限检查方法（且把该方法添加到vue原型中）
Vue.prototype.$_has = function (value) {
    let isExist = false
    // 从浏览器缓存中获取权限数组（该数组在登入成功后拉取用户的权限信息时保存在浏览器的缓存中）
    var buttonpermsStr = JSON.parse(localStorage.getItem('btnList'));
    if (buttonpermsStr === undefined || buttonpermsStr == null) {
        return false
    }
    if (buttonpermsStr.indexOf(value) > -1) {
        // 若在按钮中定义的权限字段能在后端返回的权限数组中能找到，则该按钮可显示
        isExist = true
    }
    return isExist
}

// register global utility filters
Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key])
})


Vue.config.productionTip = false;
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
